export function onScroll(ev,startX,startY) {
  return new Promise((reslove,reject)=>{
      var endX, endY;
      endX = ev.changedTouches[0].pageX;
      endY = ev.changedTouches[0].pageY;
      var direction = GetSlideDirection(startX, startY, endX, endY);
      let res = {
        direction:direction,
        scrollTop:endY
      }
      console.log('qqq',res)
      if(res){
        reslove(res)
      }else{
        reject()
      }
      

    })
}

export function GetSlideAngle(dx, dy) {
  return Math.atan2(dy, dx) * 180 / Math.PI;
}
  //根据起点和终点返回方向 1：向上，2：向下，3：向左，4：向右,0：未滑动
export function GetSlideDirection(startX, startY, endX, endY) {
    var dy = startY - endY;
    var dx = endX - startX;
    var result = 0;
    //如果滑动距离太短
    if(Math.abs(dx) < 2 && Math.abs(dy) < 2) {
        return result;
    }
    var angle = GetSlideAngle(dx, dy);
    if(angle >= -45 && angle < 45) {
        result = 'left';
    }else if (angle >= 45 && angle < 135) {
        result = 'down';
    }else if (angle >= -135 && angle < -45) {
        result = 'up';
    }
    else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) {
        result = 'right';
    }

    return result;
}
          
 
          
